<template>
	<view class="blacklist-page">
		<!-- 顶部导航栏 -->
		<view class="header">
			<view class="back-btn" @click="goBack">
				<text class="back-icon">←</text>
			</view>
			<text class="header-title">黑名单</text>
			<view class="placeholder"></view>
		</view>

		<scroll-view scroll-y class="content">
			<!-- 说明提示 -->
			<view class="tips-section">
				<view class="tips-icon">ℹ️</view>
				<view class="tips-content">
					<text class="tips-text">拉黑后，对方将无法查看您的资料，也无法向您发送消息</text>
				</view>
			</view>

			<!-- 黑名单列表 -->
			<view class="list-section" v-if="blacklist.length > 0">
				<view class="blacklist-item" v-for="(item, index) in blacklist" :key="item.id">
					<view class="user-info" @click="viewProfile(item)">
						<image class="avatar" :src="item.avatar || defaultAvatar" mode="aspectFill"></image>
						<view class="info">
							<view class="name-row">
								<text class="nickname">{{ item.nickname }}</text>
								<view class="vip-badge" v-if="item.isVip">
									<text class="vip-icon">👑</text>
								</view>
							</view>
							<view class="detail-row">
								<text class="age">{{ item.age }}岁</text>
								<text class="divider">|</text>
								<text class="location">{{ item.city }}</text>
							</view>
							<text class="block-time">拉黑时间：{{ formatDate(item.blockTime) }}</text>
						</view>
					</view>
					<view class="action-btn" @click="removeFromBlacklist(item, index)">
						<text class="btn-text">移除</text>
					</view>
				</view>
			</view>

			<!-- 空状态 -->
			<view class="empty-state" v-else>
				<text class="empty-icon">📋</text>
				<text class="empty-text">暂无黑名单用户</text>
				<text class="empty-tip">拉黑的用户将显示在这里</text>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				gatewayURL: 'http://localhost:8083',
				currentUserId: null,
				defaultAvatar: 'https://via.placeholder.com/100',
				blacklist: []
			}
		},
		onLoad() {
			// 获取当前用户ID
			this.currentUserId = uni.getStorageSync('userId') || 1
			this.loadBlacklist()
		},
		methods: {
			// 返回
			goBack() {
				uni.navigateBack()
			},
			
			// 加载黑名单
			loadBlacklist() {
				uni.showLoading({
					title: '加载中...'
				})
				
				// TODO: 调用后端接口获取黑名单
				// 模拟数据
				setTimeout(() => {
					uni.hideLoading()
					this.blacklist = [
						// {
						// 	id: 1,
						// 	userId: 10,
						// 	nickname: '测试用户1',
						// 	avatar: '',
						// 	age: 28,
						// 	city: '北京',
						// 	isVip: false,
						// 	blockTime: '2025-10-10 15:30:00'
						// }
					]
				}, 500)
			},
			
			// 格式化日期
			formatDate(dateStr) {
				if (!dateStr) return ''
				// 简单格式化，只显示日期
				return dateStr.split(' ')[0]
			},
			
			// 查看用户资料
			viewProfile(item) {
				uni.showModal({
					title: '提示',
					content: '该用户已在黑名单中，是否先移除黑名单？',
					success: (res) => {
						if (res.confirm) {
							// 移除后跳转
							const index = this.blacklist.findIndex(u => u.id === item.id)
							this.removeFromBlacklist(item, index, true)
						}
					}
				})
			},
			
			// 移除黑名单
			removeFromBlacklist(item, index, needRedirect = false) {
				uni.showModal({
					title: '移除黑名单',
					content: `确定要将"${item.nickname}"移出黑名单吗？`,
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '处理中...'
							})
							
							// TODO: 调用后端接口移除黑名单
							setTimeout(() => {
								uni.hideLoading()
								
								// 从列表中移除
								this.blacklist.splice(index, 1)
								
								uni.showToast({
									title: '已移除黑名单',
									icon: 'success'
								})
								
								// 如果需要跳转到用户资料
								if (needRedirect) {
									setTimeout(() => {
										uni.navigateTo({
											url: '/pages/user-detail/index?userId=' + item.userId
										})
									}, 1000)
								}
							}, 500)
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.blacklist-page {
		min-height: 100vh;
		background: #F5F5F5;
		display: flex;
		flex-direction: column;
	}

	/* 顶部导航栏 */
	.header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 25rpx 30rpx;
		padding-top: calc(25rpx + env(safe-area-inset-top));
		background: linear-gradient(135deg, #FF8A9B 0%, #FFB4C0 100%);
		
		.back-btn {
			width: 70rpx;
			height: 70rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background: rgba(255, 255, 255, 0.2);
			border-radius: 50%;
			
			.back-icon {
				font-size: 44rpx;
				color: #FFFFFF;
				font-weight: bold;
			}
		}
		
		.header-title {
			font-size: 38rpx;
			font-weight: bold;
			color: #FFFFFF;
		}
		
		.placeholder {
			width: 70rpx;
		}
	}

	.content {
		flex: 1;
		padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
	}

	/* 提示区域 */
	.tips-section {
		margin: 30rpx;
		padding: 25rpx;
		background: linear-gradient(135deg, #FFF4E6 0%, #FFE8CC 100%);
		border-radius: 15rpx;
		border-left: 6rpx solid #FFA726;
		display: flex;
		align-items: flex-start;
		
		.tips-icon {
			font-size: 36rpx;
			margin-right: 15rpx;
			flex-shrink: 0;
		}
		
		.tips-content {
			flex: 1;
		}
		
		.tips-text {
			font-size: 26rpx;
			color: #E65100;
			line-height: 1.6;
		}
	}

	/* 列表区域 */
	.list-section {
		padding: 0 30rpx;
		
		.blacklist-item {
			background: #FFFFFF;
			border-radius: 15rpx;
			padding: 25rpx;
			margin-bottom: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			box-shadow: 0 2rpx 15rpx rgba(0, 0, 0, 0.05);
			
			.user-info {
				flex: 1;
				display: flex;
				align-items: center;
				margin-right: 20rpx;
				
				.avatar {
					width: 100rpx;
					height: 100rpx;
					border-radius: 50%;
					margin-right: 20rpx;
					border: 3rpx solid #F0F0F0;
					flex-shrink: 0;
				}
				
				.info {
					flex: 1;
					
					.name-row {
						display: flex;
						align-items: center;
						margin-bottom: 10rpx;
						
						.nickname {
							font-size: 32rpx;
							font-weight: bold;
							color: #333333;
							margin-right: 10rpx;
						}
						
						.vip-badge {
							background: linear-gradient(135deg, #FFD700 0%, #FFA500 100%);
							padding: 4rpx 12rpx;
							border-radius: 20rpx;
							display: flex;
							align-items: center;
							
							.vip-icon {
								font-size: 20rpx;
							}
						}
					}
					
					.detail-row {
						display: flex;
						align-items: center;
						margin-bottom: 8rpx;
						
						.age,
						.location {
							font-size: 26rpx;
							color: #666666;
						}
						
						.divider {
							margin: 0 15rpx;
							color: #CCCCCC;
						}
					}
					
					.block-time {
						font-size: 22rpx;
						color: #999999;
					}
				}
			}
			
			.action-btn {
				padding: 12rpx 30rpx;
				background: linear-gradient(135deg, #FF8A9B 0%, #FF6B8A 100%);
				border-radius: 30rpx;
				flex-shrink: 0;
				
				.btn-text {
					font-size: 26rpx;
					color: #FFFFFF;
					font-weight: 500;
				}
			}
		}
	}

	/* 空状态 */
	.empty-state {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 150rpx 50rpx;
		
		.empty-icon {
			font-size: 120rpx;
			margin-bottom: 30rpx;
			opacity: 0.3;
		}
		
		.empty-text {
			font-size: 32rpx;
			color: #999999;
			margin-bottom: 15rpx;
		}
		
		.empty-tip {
			font-size: 26rpx;
			color: #CCCCCC;
		}
	}
</style>

